const mongoose = require('mongoose');
const Project = require('../src/models/project.model');
const DeployLog = require('../src/models/deploy-log.model');

async function migrateDeployStats() {
  const projects = await Project.find();
  
  for (const project of projects) {
    const logs = await DeployLog.find({ projectId: project._id });
    
    const stats = {
      totalCount: logs.length,
      successCount: logs.filter(log => log.status === 'success').length,
      failedCount: logs.filter(log => log.status === 'failed').length
    };
    
    await Project.findByIdAndUpdate(project._id, {
      deployStats: stats
    });
  }
  
  console.log('部署统计数据迁移完成');
}

migrateDeployStats().then(() => process.exit(0)); 